package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.suanhua.*;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/*
 * 算话早期风险评分
 *
 * @author:szw
 * */

public class SuanHuaRiskScoreRecordParse extends ParseBase {
    Text key = new Text();
    Text val = new Text();

    /**
     * @param context
     * @param model
     * @param successful
     * @return
     * @throws IOException
     * @throws InterruptedException
     */

    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        SuanhuaRiskScoreRecord shRecord = (SuanhuaRiskScoreRecord) model;
        SuanhuaRiskScoreData shData = shRecord.getData();

        StringBuilder sb = getBaseInfo(shRecord, successful);
        StringBuilder shSb = new StringBuilder(500);

        // retCode
        shSb.append(shData.getRetCode() == null ? "" : shData.getRetCode()).append(CRT001);
        // retMsg
        shSb.append(shData.getRetMsg() == null ? "" : shData.getRetMsg()).append(CRT001);
        // orgNum
        shSb.append(shData.getOrgNum() == null ? "" : shData.getOrgNum()).append(CRT001);
        SuanhuaRiskScore data = shData.getData();
        Afp1090 afp1090 = data.getAfp1090();
        Afp1100 afp1100 = data.getAfp1100();
        // data/appNum
        shSb.append(data.getAppNum() == null ? "" : data.getAppNum()).append(CRT001);
        // data/appDate
        shSb.append(data.getAppDate() == null ? "" : data.getAppDate()).append(CRT001);
        // data/appNo
        shSb.append(data.getAppNo() == null ? "" : data.getAppNo()).append(CRT001);
        // data/appStatus
        shSb.append(data.getAppStatus() == null ? "" : data.getAppStatus()).append(CRT001);
        // data/appValid
        shSb.append(data.getAppValid() == null ? "" : data.getAppValid()).append(CRT001);
        // data/errMsg
        shSb.append(data.getErrMsg() == null ? "" : data.getErrMsg()).append(CRT001);
        // data/appWarn
        shSb.append(data.getAppWarn() == null ? "" : data.getAppWarn()).append(CRT001);
        // data/afp1090/dataStatus
        shSb.append(afp1090.getDataStatus() == null ? "" : afp1090.getDataStatus()).append(CRT001);
        // data/afp1090/dataValid
        shSb.append(afp1090.getDataValid() == null ? "" : afp1090.getDataValid()).append(CRT001);
        // data/afp1090/dataErrMsg
        shSb.append(afp1090.getDataErrMsg() == null ? "" : afp1090.getDataErrMsg()).append(CRT001);
        // data/afp1090/zzModelIScore
        shSb.append(afp1090.getZzModelIScore() == null ? "" : afp1090.getZzModelIScore()).append(CRT001);
        // data/afp1100/dataStatus
        shSb.append(afp1100.getDataStatus() == null ? "" : afp1100.getDataStatus()).append(CRT001);
        // data/afp1100/dataValid
        shSb.append(afp1100.getDataValid() == null ? "" : afp1100.getDataValid()).append(CRT001);
        // data/afp1100/dataErrMsg
        shSb.append(afp1100.getDataErrMsg() == null ? "" : afp1100.getDataErrMsg()).append(CRT001);
        // data/afp1100/zzModelIScore
        shSb.append(afp1100.getZyModelIScore() == null ? "" : afp1100.getZyModelIScore()).append(CRT001);
        key.set(getKey());
        val.set((sb.toString() + shSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);

        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_sh_risk_score_record_inc";
    }

    @Override
    public String getType() {
        return RecordType.SUANHUA_RISK_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "算话早期风险评分";
    }
}
